<template>
  <div>
    <div style="background: #e8f1f8">
      <div class="det_tab">
        <div style="text-align: center; margin: 10px">
          {{ form.CheckTaskName }}
        </div>
        <div class="det_tab_item">
          <van-cell-group :border="border">
            <van-field
              label="检查类型"
              class="input_text"
              :value="form.CheckTypeName"
              readonly
            />
            <!-- <van-field
              label="来源计划"
              class="input_text"
              autosize
                type="textarea"
                   rows="1"
              :value="form.CheckPlanName"
              readonly
              @click="goFromDetail()"
               right-icon="arrow"
            /> -->
            <van-field
              label="任务发起人"
              class="input_text"
              :value="form.CreateChnName"
              readonly
            />
            <!-- <van-field
            label="来源"
            class="input_text"
            :value="
              form.OriginType == 1
                ? '检查表检查'
                : form.StatusName == 2
                ? '依据检查'
                : '随手拍'
            "
            readonly
          /> -->
            <van-field
              label="任务发起时间"
              class="input_text"
              :value="getDateTime(form.CreateDate)"
              readonly
            />
            <!-- <van-field
              label="检查人"
              class="input_text"
              :value="form.CheckNames"
              readonly
            /> -->
            <van-field
              label="检查时间段"
              class="input_text"
              rows="1"
              autosize
              type="textarea"
              :value="getDateTime(form.StartDate) + '至' + getDateTime(form.EndDate)"
              readonly
            />
            <van-field
              label="检查要求"
              class="input_text"
              :value="form.CheckRequirement || '暂无检查要求'"
              readonly
            />
            <van-field
              v-if="form.Status == 10 || form.Status == 20"
              label="检查记录"
              class="input_text"
              :value="
                '隐患：' + form.HiddenDangerCnt + ' /检查：' + form.CheckCnt
              "
              right-icon="arrow"
              readonly
              @click="goMyTaskHistoryList('All')"
            />
            <van-field
              v-if="form.Status == 0"
              label="检查记录"
              class="input_text"
              :value="
                '隐患：' + form.HiddenDangerCnt + ' /检查：' + form.CheckCnt
              "
              readonly
            />
            <!-- <van-field
              label="检查现场照片"
              class="input_text"
              :value="'已上传' + form.PhotoCnt + '张现场照片'"
              readonly
              right-icon="arrow"
              @click="goMyTaskFileList()"
            /> -->
          </van-cell-group>
        </div>
      </div>

      <div class="det_tab" v-if="form.Users.length > 0">
        <div class="det_tab_item">
          <div class="operate_det">
            <div style="margin-bottom: 10px">检查人</div>
            <div class="operate_list">
              <van-row
                v-for="(item, index) in form.Users"
                :key="index"
                class="operate_row"
                @click="goMyTaskHistoryList(item.UserName)"
              >
                <van-col span="1">{{ index + 1 }}</van-col>
                <van-col offset="1" span="17">{{ item.ChnName }} </van-col>
                <van-col offset="1" span="4">
                  <van-tag v-if="item.Status == 0" size="mini" color="grey"
                    >未开始</van-tag
                  >
                  <van-tag v-if="item.Status == 10" size="mini" color="#1989fa"
                    >进行中</van-tag
                  >
                  <van-tag v-if="item.Status == 20" size="mini" type="warning"
                    >已结束</van-tag
                  >
                  <!-- <van-tag  size="mini" color="#7232dd">标签</van-tag> -->
                </van-col>
              </van-row>
            </div>
          </div>
        </div>
        <div v-if="form.Status == 10" class="btns m-10">
          <van-button type="green" @click="handleClose()">
            结束任务
          </van-button>
        </div>
      </div>
      
    </div>
  </div>
</template>

<script>
import { getCheckPlanFollowDetail, handleClose } from "@/api/sytech/sytechDangerCheckTask";
import { Dialog } from "vant";
import { getDateTime } from "@/utils/getDate";

// import { deepClone } from "@/utils";
export default {
  components: {},
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      border: false,
      form: {
        Users: [],
      },
    };
  },
  created() {
    this.geDetail();
  },
  methods: {
    // goMyTaskFileList() {
    //   this.$router.push(
    //     "/SytechDangerCheckTaskFileList?ctCode=" + this.form.CTCode
    //   );
    // },

    getDateTime(value) {
      return getDateTime(value);
    },
    goMyTaskHistoryList(userName) {
      // if (this.form.Status == 0) {
      //   return;
      // } else {
      //   this.$router.push(
      //     "/SytechDanger/DangerCheckTaskDetailList?ctCode=" +
      //       this.form.CTCode +
      //       "&userName=" +
      //       userName
      //   );
      // }
    },

    // 获取详情
    geDetail() {
      getCheckPlanFollowDetail({ id: this.id }).then((res) => {
        this.form = res.data;
      });
    },

    handleClose() {
      Dialog.confirm({
        title: "询问",
        message: "您确定要结束当前检查任务吗?",
      })
        .then(() => {
          // on confirm
          handleClose({ id: this.form.ID }).then((res) => {
            this.$toast.success("结束成功！");
            this.$router.goRefresh();
            // console.log('asdasdsad',res);
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>

<style lang="less" scoped>
/*
        .main {
            height: 100vh;
        }
    */
.bottom-btns {
  margin-top: 10px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .submit-btn {
    width: 32%;
    height: 30px;
    font-size: 12px;
  }
  .delete-btn {
    width: 100%;
    height: 30px;
    font-size: 12px;
  }
}
.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}
.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    font-size: 12px;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      /*margin-bottom: 10px;*/
    }
  }
}
</style>
